// cnpm install mysql
var mysql = require('mysql');

var conn = mysql.createConnection({
	host: 'localhost',
	user: 'root',
	password: 'root',
	database: 'test'
});

conn.connect();

conn.query('select 1+1 as total', (err, results, fields) => {
	if (err) throw err;
	console.log('result =>', results[0].total);
	console.log('results =>', results);
});

var sql = 'insert into person(name) values(?)';
var sqlParam = ['tom'];

conn.query(sql, sqlParam, (err, result) => {
	if (err) {
		console.error(err);
		return;
	}
	console.log('insert result =>', result);
});

sql = 'update person set name = ? where id = ?';
sqlParam = ['abc', 1];

conn.query(sql, sqlParam, (err, result) => {
	if (err) {
                console.error(err);
                return;
        }
        console.log('update result =>', result);
});

sql = 'delete from person where id = 1';

conn.query(sql, (err, result) => {
	if (err) {
                console.error(err);
                return;
        }
        console.log('delete result =>', result);
});

conn.end();



